using System;
using System.Collections.Generic;
using System.Reflection;
using TestCases.CompareAssert.Core.Comparers.Interfaces;
using TestCases.CompareAssert.Core.Selectors;

namespace TestCases.CompareAssert.Core.Comparers.Members
{
    public class FieldsComparer : MembersComparer<FieldInfo>
    {
        public const string IdentifiableName = "FieldsComparer";
        public const string FieldEntity = "field";

        public FieldsComparer()
        {            
        }
        
        public FieldsComparer(ITypeSelector typeSelector) : base(typeSelector)
        {            
        }
        
        public FieldsComparer(IObjectComparer comparer) : base(comparer)
        {
        }

        public FieldsComparer(ITypeSelector typeSelector, IObjectComparer comparer) : base(typeSelector, comparer)
        {
        }
        
        public override string EntityName { get { return FieldEntity; } }
        public override string Name { get { return IdentifiableName; } }

        public override IEnumerable<string> GetMemberNames(Type type, BindingFlags flags)
        {
            return ExtractMemberNames(type.GetFields(flags));
        }

        public override FieldInfo GetMember(Type type, string name, BindingFlags flags)
        {
            return type.GetField(name, flags);
        }

        public override object GetMemberValue(FieldInfo member, object instance)
        {
            return member.GetValue(instance);
        }

    }
}